<template>
  <div>
    <van-nav-bar
      :title="$route.meta.title"
      left-arrow
      @click-left="$router.back()"
    />
    <br/>
    <br/>
    <van-form @submit="onSubmit">
        <van-field
          v-model="reginfo.phone"
          name="手机号"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          v-model="reginfo.nickname"
          name="昵称"
          label="昵称"
          placeholder="昵称"
          :rules="[{ required: true, message: '请填写昵称' }]"
        />
        <van-field
          v-model="reginfo.password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
          v-model="reginfo.password2"
          type="password"
          name="确认密码"
          label="确认密码"
          placeholder="确认密码"
          :rules="[{ required: true, message: '请确认密码' }]"
        />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交 </van-button>
      </div>
    </van-form>
    <br/>
    <p style="text-align:center;">
        <router-link to="/login">已有账号？立即登录</router-link> 
    </p>
  </div>
</template>

<script>
import { Notify,Toast } from 'vant';
import { reg } from '@/common/request';
export default {
    data(){
        return{
            reginfo:{
              nickname:"",
              phone:"",
              password2:"",
              password:""
            }
        }
    },
    created(){},
    methods:{
      async onSubmit(){
         if(this.reginfo.password != this.reginfo.password2){
              Notify({ type: 'warning', message: "两次密码不一致" });
              return;
         }
         await reg(this.reginfo);
         Toast({
           type:"success",
           message:"注册成功",
           onClose:()=>{
              this.$router.back();
           }
         });
      }
    },
    components:{}
}

</script>
<style scoped>
</style>